package com.shelpe.services.sinbadgateway.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.shelpe.services.sinbadgateway.dto.PurchaseUserLoginDto;
import com.shelpe.services.sinbadgateway.service.LoginService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/sinbadgateway")
public class PurchaseUserLoginController {
	
	@Autowired
	private LoginService loginService;
	
	@RequestMapping(method = RequestMethod.POST, path = "/purchaseUsers/{user_id}/@login")
	@ResponseBody
	public PurchaseUserLoginDto purchaseUserLogin(@PathVariable("user_id") Long userId, @RequestBody PurchaseUserLoginDto dto) {
		
		String nick = dto.getNick();
		log.info("purchaseUserLogin: userId {}, nick {}", userId, nick);
		
		if(userId == null && nick == null){
			log.error("purchaseUserLogin: both userId and nick are null");
			dto.setResult(false);
			dto.setMessage("both userId and nick are null");
			
			return dto;
		}
		
		dto.setUserId(userId);
		dto.setNick(nick);
		boolean result = loginService.purchaseUserLoginCheck(dto);
		dto.setResult(result);

		return dto;
	}

}
